package fifteen;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

public class OOSDemo {
    public static void main(String[] args) throws IOException {
        String name = "zs";
        int age = 18;
        String gender = "男";
        String[] otherInfo = {"是一名学生","黑龙江佳木斯的","喜欢打篮球"};
        Student zs = new Student(name,age,gender,otherInfo);
        System.out.println(zs.toString());
        /**
         * 对象输出流的writeObject()可以进行对象的序列化
         * 对象输出流在序列化对象时，必须保证序列化对象必须实现Serializable接口
         * 若没有实现序列化接口会发生NotSerializableException异常
         */
        FileOutputStream fos = new FileOutputStream("./a/student.obj"); // 写入到student.obj
        ObjectOutputStream oos = new ObjectOutputStream(fos); // 将文件输出流fos序列化成oos
        oos.writeObject(zs); // 利用序列化的writeObject()方法将对象zs写到oos
        System.out.println("写出完毕");
        oos.close();
    }
}
